﻿// This file is part of Code4Public (http://code4public.codeplex.com)
// Copyright 2011 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
// ------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Code4Public.ThemeDesigners
{
    [DefaultEvent("FontPropertiesChanged")]
    [DefaultProperty("Caption")]
    public partial class ThemeFontDesigner : UserControl
    {
        public ThemeFontDesigner()
        {
            InitializeComponent();
        }

        private bool eventSuspended = false;

        [Browsable(true)]
        public string Caption
        {
            get
            {
                return groupFont.Text;
            }

            set
            {
                this.groupFont.Text = value;
            }
        }

        public event EventHandler FontPropertiesChanged;

        public void SuspendEventRaising()
        {
            eventSuspended = true;
        }

        public void ResumeEventRaising()
        {
            eventSuspended = false;
        }

        private void cbBold_CheckedChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && FontPropertiesChanged != null)
                FontPropertiesChanged(this, new EventArgs());
        }

        private void cbItalic_CheckedChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && FontPropertiesChanged != null)
                FontPropertiesChanged(this, new EventArgs());
        }

        private void colorPicker_ColorChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && FontPropertiesChanged != null)
                FontPropertiesChanged(this, new EventArgs());
        }

        private void numericUpDownFontSize_ValueChanged(object sender, EventArgs e)
        {
            if (showFontSize && !eventSuspended && FontPropertiesChanged != null)
                FontPropertiesChanged(this, new EventArgs());
        }

        private bool showFontSize = true;
        public bool ShowFontSize
        {
            get
            {
                return showFontSize;
            }

            set
            {
                showFontSize = value;
                lblFontSize.Visible = value;
                numericUpDownFontSize.Visible = value;
            }
        }

        public bool FontBold
        {
            get
            {
                return cbBold.Checked;
            }

            set
            {
                cbBold.Checked = value;
            }
        }

        public bool FontItalic
        {
            get
            {
                return cbItalic.Checked;
            }

            set
            {
                cbItalic.Checked = value;
            }
        }

        public Color FontColor
        {
            get
            {
                return colorPicker.Color;
            }

            set
            {
                colorPicker.Color = value;
            }
        }

        public int FontSize
        {
            get
            {
                return (int)numericUpDownFontSize.Value;
            }

            set
            {
                numericUpDownFontSize.Value = value;
            }
        }

    }
}
